Pandas - apply a custom function to two columns after a group_by - reformulated